/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.java.controller;

import com.java.common.Encryption;
import com.java.editor.LoaiBiaEditor;
import com.java.editor.LoaiSachEditor;
import com.java.editor.NxbEditor;
import com.java.editor.QuyenEditor;
import com.java.editor.TacGiaEditor;
import com.java.editor.TheLoai1Editor;
import com.java.editor.TheLoai2Editor;
import com.java.editor.TheLoai3Editor;
import com.java.editor.TinhEditor;
import com.java.mapbean.Loaibia;
import com.java.mapbean.Loaisach;
import com.java.mapbean.Nguoidung;
import com.java.mapbean.Nhaxuatban;
import com.java.mapbean.Quyen;
import com.java.mapbean.Sach;
import com.java.mapbean.Tacgia;
import com.java.mapbean.Theloai1;
import com.java.mapbean.Theloai2;
import com.java.mapbean.Theloai3;
import com.java.mapbean.Tinh;
import com.java.service.LoaiBiaService;
import com.java.service.LoaiSachService;
import com.java.service.NguoiDungService;
import com.java.service.NhaXuatBanService;
import com.java.service.QuyenService;
import com.java.service.SachService;
import com.java.service.TacGiaService;
import com.java.service.TheLoai1Service;
import com.java.service.TheLoai3Service;
import com.java.service.Theloai2Service;
import com.java.service.TinhService;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author quannq
 */
@Controller
@RequestMapping(value = "admin")
public class AdminController {

    private SachService sachService = new SachService();
    private TacGiaService tacgiaService = new TacGiaService();
    private TheLoai1Service theLoai1Service = new TheLoai1Service();
    private Theloai2Service theLoai2Service = new Theloai2Service();
    private TheLoai3Service theLoai3Service = new TheLoai3Service();
    private LoaiBiaService loaiBiaService = new LoaiBiaService();
    private LoaiSachService loaiSachService = new LoaiSachService();
    private NhaXuatBanService nhaXuatBanService = new NhaXuatBanService();
    private TinhService tinhService = new TinhService();
    private NguoiDungService nguoidungService = new NguoiDungService();
    private QuyenService quyenService = new QuyenService();
    private String directory = "E:\\WORKSPACE\\JAVA\\bookshop\\web\\image\\sell\\";

    @InitBinder
    protected void initBinder(HttpServletRequest request,
            ServletRequestDataBinder binder) throws Exception {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        CustomDateEditor editor = new CustomDateEditor(df, true);
        binder.registerCustomEditor(Date.class, editor);
        binder.registerCustomEditor(Theloai1.class, new TheLoai1Editor(this.theLoai1Service));
        binder.registerCustomEditor(Theloai2.class, new TheLoai2Editor(this.theLoai2Service));
        binder.registerCustomEditor(Theloai3.class, new TheLoai3Editor(this.theLoai3Service));
        binder.registerCustomEditor(Tacgia.class, new TacGiaEditor(this.tacgiaService));
        binder.registerCustomEditor(Loaibia.class, new LoaiBiaEditor(this.loaiBiaService));
        binder.registerCustomEditor(Loaisach.class, new LoaiSachEditor(this.loaiSachService));
        binder.registerCustomEditor(Nhaxuatban.class, new NxbEditor(this.nhaXuatBanService));
        binder.registerCustomEditor(Tinh.class, new TinhEditor(this.tinhService));
        binder.registerCustomEditor(Quyen.class, new QuyenEditor(this.quyenService));

        // binder.registerCustomEditor(MultipartFilter.class,new StringMultipartFileEditor());
        request.setCharacterEncoding("UTF-8");
        //binder.registerCustomEditor(int.class, new IntEditor());
    }

    /*
     * Begin management book
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public String listSach(ModelMap model) {
        model.addAttribute("Sach", sachService.getAll());
        model.addAttribute("adminpage", "AllSach.jsp");
        return "Admin";
    }

    @RequestMapping(value = "infosach/{id}", method = RequestMethod.GET)
    public ModelAndView infoSach(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("sach", sachService.findId(id));
        model.addAttribute("theLoai1", theLoai1Service.getAll());
        model.addAttribute("theLoai2", theLoai2Service.getAll());
        model.addAttribute("theLoai3", theLoai3Service.getAll());
        model.addAttribute("loaiSach", loaiSachService.getAll());
        model.addAttribute("loaiBia", loaiBiaService.getAll());
        model.addAttribute("nhaXuatBan", nhaXuatBanService.getAll());
        model.addAttribute("tacGia", tacgiaService.getAll());
        return new ModelAndView("ajax/infoSach");
    }

    @RequestMapping(value = "addsach", method = RequestMethod.GET)
    public ModelAndView addSachForm(ModelMap model) {
        model.addAttribute("sach", new Sach());
        model.addAttribute("theLoai1", theLoai1Service.getAll());
        model.addAttribute("theLoai2", theLoai2Service.getAll());
        model.addAttribute("theLoai3", theLoai3Service.getAll());
        model.addAttribute("loaiSach", loaiSachService.getAll());
        model.addAttribute("loaiBia", loaiBiaService.getAll());
        model.addAttribute("nhaXuatBan", nhaXuatBanService.getAll());
        model.addAttribute("tacGia", tacgiaService.getAll());
        return new ModelAndView("ajax/AddSach");
    }

    @RequestMapping(value = "addNewSach", method = RequestMethod.POST)
    public String addSachAction(@ModelAttribute Sach sach, @RequestParam("anh") MultipartFile anh,
            ModelMap model, HttpServletRequest request) throws IOException {
        String extension;
        if (anh.getContentType().contains("pn")) {
            extension = "png";
        } else {
            extension = "jpg";
        }
        String file = sach.getTensach() + "." + extension;
        anh.transferTo(new File(directory + file));
        anh.transferTo(new File(request.getRealPath("/image/") + file));
        sach.setAnhbia(file);
        sachService.saveSach(sach);
        return "redirect:/admin";
    }

    @RequestMapping(value = "updateSach", method = RequestMethod.POST)
    public String updateSachAction(@ModelAttribute Sach sach, @RequestParam("anh") MultipartFile anh,
            ModelMap model, HttpServletRequest request) throws IOException {
        if (!anh.isEmpty()) {
            System.out.println(anh.getOriginalFilename());
            System.out.println(anh.getContentType());
            String extension;
            if (anh.getContentType().contains("pn")) {
                extension = "png";
            } else {
                extension = "jpg";
            }
            String file = sach.getTensach() + "." + extension;
            anh.transferTo(new File(directory + file));
            anh.transferTo(new File(request.getRealPath("/image")+"/" + file));
            sach.setAnhbia(file);
        }

        sachService.updateSach(sach);
        return "redirect:/admin";
    }

    @RequestMapping(value = "loadTL2/{idTL1}", method = RequestMethod.GET)
    public ModelAndView loadTL2(@PathVariable(value = "idTL1") int idTL1,
            ModelMap model) {
        model.addAttribute("TheLoai2", theLoai1Service.findId(idTL1).getTheloai2s());
        return new ModelAndView("ajax/LoadTheLoai");
    }

    @RequestMapping(value = "loadTL3/{idTL2}", method = RequestMethod.GET)
    public ModelAndView loadTL3(@PathVariable(value = "idTL2") int idTL2,
            ModelMap model) {
        model.addAttribute("TheLoai3", theLoai2Service.findId(idTL2).getTheloai3s());
        return new ModelAndView("ajax/LoadTheLoai");
    }
    /*
     * End management book
     */
    /*
     * Begin management Auth
     */

    @RequestMapping(value = "tacgia", method = RequestMethod.GET)
    public String listTacGia(ModelMap model) {
        model.addAttribute("TacGia", tacgiaService.getAll());
        model.addAttribute("adminpage", "AllTacGia.jsp");
        return "Admin";
    }

    @RequestMapping(value = "addtacgia", method = RequestMethod.GET)
    public ModelAndView viewFrmAddAuth(ModelMap model) {
        model.addAttribute("tacgia", new Tacgia());
        return new ModelAndView("ajax/AddTacGia");
    }

    @RequestMapping(value = "tacgia", method = RequestMethod.POST)
    public String addNewAuth(@ModelAttribute Tacgia tacgia, ModelMap model) {
        tacgiaService.saveSach(tacgia);
        model.addAttribute("adminpage", "AllTacGia.jsp");
        return "Admin";
    }

    @RequestMapping(value = "infotacgia/{id}", method = RequestMethod.GET)
    public ModelAndView viewFrmUpdate(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("tacgia", tacgiaService.findId(id));
        return new ModelAndView("ajax/infoTacGia");
    }

    @RequestMapping(value = "updatetacgia", method = RequestMethod.GET)
    public String viewFrmUpdate(@ModelAttribute Tacgia tacgia, ModelMap model) {
        tacgiaService.updateTacgia(tacgia);
        model.addAttribute("adminpage", "AllTacGia.jsp");
        return "Admin";
    }

    @RequestMapping(value = "listsachtacgia/{id}", method = RequestMethod.GET)
    public ModelAndView getSachTG(@PathVariable(value = "id") int id, ModelMap model) {
        Tacgia tacgia = tacgiaService.findId(id);
        model.addAttribute("theloai1", tacgia);
        model.addAttribute("sachtg", "<p>" + tacgia.getTentacgia() + " &gt;&gt; Sách </p>");
        return new ModelAndView("ajax/ListSach");
    }
    /*
     * End management Auth
     */
    /*
     * Begin management nxb
     */

    @RequestMapping(value = "nhaxuatban", method = RequestMethod.GET)
    public String listNXB(ModelMap model) {
        model.addAttribute("nhaxuatbans", nhaXuatBanService.getAll());
        model.addAttribute("adminpage", "AllNXB.jsp");
        return "Admin";
    }

    @RequestMapping(value = "addnhaxuatban", method = RequestMethod.GET)
    public ModelAndView viewFrmAddNXB(ModelMap model) {
        model.addAttribute("nhaxuatban", new Nhaxuatban());
        return new ModelAndView("ajax/AddNXB");
    }

    @RequestMapping(value = "nhaxuatban", method = RequestMethod.POST)
    public String addNewAuth(@ModelAttribute Nhaxuatban nhaxuatban, ModelMap model) {
        nhaXuatBanService.saveNxb(nhaxuatban);
        model.addAttribute("adminpage", "AllNXB.jsp");
        return "Admin";
    }

    @RequestMapping(value = "infonhaxuatban/{id}", method = RequestMethod.GET)
    public ModelAndView viewFrmUpdateNXB(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("nhaxuatban", nhaXuatBanService.findId(id));
        return new ModelAndView("ajax/infoNXB");
    }

    @RequestMapping(value = "updatenhaxuatban", method = RequestMethod.GET)
    public String viewFrmUpdateNXB(@ModelAttribute Nhaxuatban nhaxuatban, ModelMap model) {
        nhaXuatBanService.updateNxb(nhaxuatban);
        model.addAttribute("adminpage", "AllNXB.jsp");
        return "Admin";
    }

    @RequestMapping(value = "listsachnxb/{id}", method = RequestMethod.GET)
    public ModelAndView getSachNXB(@PathVariable(value = "id") int id, ModelMap model) {
        Nhaxuatban nhaxuatban = nhaXuatBanService.findId(id);
        model.addAttribute("theloai1", nhaxuatban);
        model.addAttribute("sachnxb", "<p>" + nhaxuatban.getTennxb() + " &gt;&gt; Sách </p>");
        return new ModelAndView("ajax/ListSach");
    }
    /*
     * End management nxb
     */

    /*
     * Begin management Province
     */
    @RequestMapping(value = "tinh", method = RequestMethod.GET)
    public String showTinh(ModelMap model) {
        model.addAttribute("tinhs", tinhService.getAll());
        model.addAttribute("adminpage", "AllTinh.jsp");
        return "Admin";
    }

    @RequestMapping(value = "addtinh", method = RequestMethod.GET)
    public String viewFrmAddPro(ModelMap model) {
        model.addAttribute("tinh", new Tinh());
        model.addAttribute("adminpage", "AddTinh.jsp");
        return "Admin";
    }

    @RequestMapping(value = "addtinh", method = RequestMethod.POST)
    public String addNewTinh(@ModelAttribute Tinh tinh, ModelMap model) {
        tinhService.saveTinh(tinh);
        model.addAttribute("adminpage", "AllTinh.jsp");
        return "Admin";
    }

    @RequestMapping(value = "tinh/{id}", method = RequestMethod.GET)
    public String viewFrmUpdatePro(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("tinh", tinhService.findId(id));
        model.addAttribute("adminpage", "Tinh.jsp");
        return "Admin";
    }

    @RequestMapping(value = "updatetinh", method = RequestMethod.POST)
    public String updatePro(@ModelAttribute Tinh tinh, ModelMap model) {
        tinhService.updateTinh(tinh);
        model.addAttribute("adminpage", "AllTinh.jsp");
        return "Admin";
    }
    /*
     * End management Province
     */
    /*
     * Begin management Category 1
     */

    @RequestMapping(value = "theloaisach")
    public String listTheLoai(ModelMap model) {
        model.addAttribute("theloai1", theLoai1Service.getAll());
        model.addAttribute("adminpage", "TheLoai.jsp");
        return "Admin";
    }

    @RequestMapping(value = "addtheloai1", method = RequestMethod.GET)
    public ModelAndView viewFrmAddTL1(ModelMap model) {
        model.addAttribute("theloai1", new Theloai1());
        return new ModelAndView("ajax/AddTheLoai1");
    }

    @RequestMapping(value = "addtheloai1", method = RequestMethod.POST)
    public String addNewTL1(@ModelAttribute Theloai1 theloai1, ModelMap model) {
        theLoai1Service.saveTheLoai1(theloai1);
        return "redirect:/admin/theloaisach";
    }

    @RequestMapping(value = "infotheloai1/{idtl1}", method = RequestMethod.GET)
    public ModelAndView viewFrmUpdateTL1(@PathVariable(value = "idtl1") int idtl1, ModelMap model) {
        model.addAttribute("theloai1", theLoai1Service.findId(idtl1));
        return new ModelAndView("ajax/infoTheLoai1");
    }

    @RequestMapping(value = "theloai2_select/{id}", method = RequestMethod.GET)
    public ModelAndView getTL1(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("theloai1", theLoai1Service.findId(id));
        return new ModelAndView("ajax/TheLoai2_select");
    }

    @RequestMapping(value = "updatetheloai1", method = RequestMethod.POST)
    public String updateTL1(@ModelAttribute Theloai1 theloai1, ModelMap model) {
        theLoai1Service.updateTheloai1(theloai1);
        return "";
    }

    @RequestMapping(value = "theloai2_list/{idtl1}", method = RequestMethod.GET)
    public ModelAndView getTL2List(@PathVariable(value = "idtl1") int idtl1, ModelMap model) {
        Theloai1 theloai1 = theLoai1Service.findId(idtl1);
        model.addAttribute("theloai1", theloai1);
        model.addAttribute("tl2", "<p>" + theloai1.getTentl1() + "&gt;&gt;Thể Loại 2 &gt;&gt; Danh Sách</p>");
        return new ModelAndView("ajax/TheLoai2");
    }

    @RequestMapping(value = "theloai3_list/{idtl1}", method = RequestMethod.GET)
    public ModelAndView getTL3List(@PathVariable(value = "idtl1") int idtl1, ModelMap model) {
        Theloai1 theloai1 = theLoai1Service.findId(idtl1);
        model.addAttribute("theloai1", theloai1);
        model.addAttribute("tl1_3", "<p>" + theloai1.getTentl1() + "&gt;&gt;Thể Loại 3&gt;&gt; Danh Sách</p>");
        return new ModelAndView("ajax/TheLoai3");
    }

    @RequestMapping(value = "listsachtl1/{idtl1}", method = RequestMethod.GET)
    public ModelAndView getSachTl1(@PathVariable(value = "idtl1") int idtl1, ModelMap model) {
        Theloai1 theloai1 = theLoai1Service.findId(idtl1);
        model.addAttribute("theloai1", theloai1);
        model.addAttribute("sach1", "<p>" + theloai1.getTentl1() + " &gt;&gt; Sách </p>");
        return new ModelAndView("ajax/ListSach");
    }

    /*
     * End management Category 1
     */
    /*
     * Begin management Category 2
     */
    @RequestMapping(value = "addtheloai2", method = RequestMethod.GET)
    public ModelAndView viewFrmAddTL2(ModelMap model) {
        model.addAttribute("theloai2", new Theloai2());
        model.addAttribute("theloai1", theLoai1Service.getAll());
        return new ModelAndView("ajax/AddTheLoai2");
    }

    @RequestMapping(value = "addtheloai2", method = RequestMethod.POST)
    public String addNewTL2(@ModelAttribute Theloai2 theloai2, ModelMap model) {
        theLoai2Service.saveTheLoai2(theloai2);
        return "redirect:/admin/theloaisach";
    }

    @RequestMapping(value = "infotheloai2/{id}", method = RequestMethod.GET)
    public ModelAndView viewFrmUpdateTL2(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("theloai2", theLoai2Service.findId(id));
        return new ModelAndView("ajax/infoTheLoai2");
    }

    @RequestMapping(value = "updatetheloai2", method = RequestMethod.POST)
    public String updateTL2(@ModelAttribute Theloai2 theloai2, ModelMap model) {
        theLoai2Service.updateTheloai2(theloai2);
        return "";
    }

    @RequestMapping(value = "listsachtl2/{idtl2}", method = RequestMethod.GET)
    public ModelAndView getSachTl2(@PathVariable(value = "idtl2") int idtl2, ModelMap model) {
        Theloai2 theloai2 = theLoai2Service.findId(idtl2);
        model.addAttribute("theloai1", theloai2);
        model.addAttribute("sach2", "<p>" + theloai2.getTheloai1().getTentl1()
                + "&gt;&gt;" + theloai2.getTentl2() + " &gt;&gt; Sách </p>");
        return new ModelAndView("ajax/ListSach");
    }

    @RequestMapping(value = "theloai3_list2/{idtl2}", method = RequestMethod.GET)
    public ModelAndView getTL3List2(@PathVariable(value = "idtl2") int idtl2, ModelMap model) {
        Theloai2 theloai2 = theLoai2Service.findId(idtl2);
        model.addAttribute("theloai1", theloai2);
        model.addAttribute("tl2_3", "<p>" + theloai2.getTheloai1().getTentl1()
                + "&gt;&gt;" + theloai2.getTentl2() + "&gt;&gt;Thể loại 3 &gt;&gt; Danh Sách</p>");
        return new ModelAndView("ajax/TheLoai3");
    }

    /*
     * End management Category 2
     */
    /*
     * Begin management Category 3
     */
    @RequestMapping(value = "addtheloai3", method = RequestMethod.GET)
    public ModelAndView viewFrmAddTL3(ModelMap model) {
        model.addAttribute("theloai3", new Theloai3());
        model.addAttribute("theloai1", theLoai1Service.getAll());
        model.addAttribute("theloai2", theLoai2Service.getAll());
        return new ModelAndView("ajax/AddTheLoai3");
    }

    @RequestMapping(value = "addtheloai3", method = RequestMethod.POST)
    public String addNewTL3(@ModelAttribute Theloai3 theloai3, ModelMap model) {
        theLoai3Service.saveTheLoai3(theloai3);
        return "redirect:/admin/theloaisach";
    }

    @RequestMapping(value = "infotheloai3/{id}", method = RequestMethod.GET)
    public ModelAndView viewFrmUpdateTL3(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("theloai3", theLoai3Service.findId(id));
        return new ModelAndView("ajax/infoTheLoai3");
    }

    @RequestMapping(value = "updatetheloai3", method = RequestMethod.POST)
    public String updateTL3(@ModelAttribute Theloai3 theloai3, ModelMap model) {
        theLoai3Service.updateTheLoai3(theloai3);
        return "";
    }

    @RequestMapping(value = "listsachtl3/{idtl3}", method = RequestMethod.GET)
    public ModelAndView getSachTl3(@PathVariable(value = "idtl3") int idtl3, ModelMap model) {
        Theloai3 theloai3 = theLoai3Service.findId(idtl3);
        model.addAttribute("theloai1", theloai3);
        model.addAttribute("sach3", "<p>" + theloai3.getTheloai1().getTentl1()
                + "&gt;&gt;" + theloai3.getTheloai2().getTentl2() + "&gt;&gt;" + theloai3.getTentl3()
                + " &gt;&gt; Sách </p>");
        return new ModelAndView("ajax/ListSach");
    }
    /*
     * End management Category 3
     */
    /*
     * Begin management User
     */

    @RequestMapping(value = "nhanvien")
    public String listNhanVien(ModelMap model) {
        model.addAttribute("nhanvien", nguoidungService.getEmp());
        model.addAttribute("adminpage", "AllNhanVien.jsp");
        return "Admin";
    }

    @RequestMapping(value = "khachhang")
    public String listKhachHang(ModelMap model) {
        model.addAttribute("khachhang", nguoidungService.getCus());
        model.addAttribute("adminpage", "AllKhachHang.jsp");
        return "Admin";
    }

    @RequestMapping(value = "infonhanvien/{id}", method = RequestMethod.GET)
    public ModelAndView viewFrmUpdateNV(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("Tinh", tinhService.getAll());
        model.addAttribute("Quyen", quyenService.getAdmin());
        model.addAttribute("nhanvien", nguoidungService.findId(id));
        return new ModelAndView("ajax/InfoNhanVien");
    }

    @RequestMapping(value = "infokhachhang/{id}", method = RequestMethod.GET)
    public ModelAndView viewFrmUpdateKH(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("Tinh", tinhService.getAll());
        model.addAttribute("nhavien", nguoidungService.findId(id));
        model.addAttribute("Quyen", quyenService.getAdmin());
        return new ModelAndView("ajax/InfoKhachhang");
    }

    @RequestMapping(value = "updatenhanvien", method = RequestMethod.POST)
    public String updateNhanVien(@ModelAttribute Nguoidung nhanvien, ModelMap model) {
        nhanvien.setAvatar(nhanvien.getDanhxung() == 1 ? "woman.png" : "man.png");
        //nhanvien.setPassword(Encryption.encrypt(nhanvien.getPassword()));
        nguoidungService.updateNguoiDung(nhanvien);
        return "redirect:/admin/nhanvien";
    }

    @RequestMapping(value = "addnhanvien", method = RequestMethod.GET)
    public ModelAndView viewFrmAddNV(ModelMap model) {
        model.addAttribute("Tinh", tinhService.getAll());
        model.addAttribute("Quyen", quyenService.getAdmin());
        model.addAttribute("nhanvien", new Nguoidung());
        return new ModelAndView("ajax/AddNhanVien");
    }

    @RequestMapping(value = "addnhanvien", method = RequestMethod.POST)
    public String addNewNV(@ModelAttribute Nguoidung nhanvien, ModelMap model) {
        nhanvien.setPassword(Encryption.encrypt(nhanvien.getPassword()));
        nhanvien.setAvatar(nhanvien.getDanhxung() == 1 ? "woman.png" : "man.png");
        nguoidungService.saveNguoiDung(nhanvien);
        return "redirect:/admin/nhanvien";
    }
    /*
     * End management User
     */
    /*
     * Begin management Order
     */

    @RequestMapping(value = "listhoadon/{id}", method = RequestMethod.GET)
    public ModelAndView listOrder(@PathVariable(value = "id") int id, ModelMap model) {
        model.addAttribute("khachhang", nguoidungService.findId(id));
        return new ModelAndView("ajax/ListHoaDon");
    }
    /*
     * End management Order
     */
}
